package entity.CRM;

import entity.FRM.CreditAccount;
import entity.FRM.CustomerInvoice;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

@Entity
public class Customer extends SaleLead implements Serializable {
    @OneToOne
    private CreditAccount creditAccount;
    @ManyToOne(cascade= CascadeType.ALL)
    private CustomerExecutive customerExecutive;
    @OneToMany
    private List<SaleOrder> saleOrders = new ArrayList<SaleOrder>();
    @OneToMany
    private List<CustomerInvoice> customerInvoices = new ArrayList<CustomerInvoice>();
    
    public CustomerExecutive getCustomerExecutive() {
        return customerExecutive;
    }

    public void setCustomerExecutive(CustomerExecutive customerExecutive) {
        this.customerExecutive = customerExecutive;
    }

    public List<SaleOrder> getSaleOrders() {
        return saleOrders;
    }

    public void setSaleOrders(List<SaleOrder> saleOrders) {
        this.saleOrders = saleOrders;
    }

    public CreditAccount getCreditAccount() {
        return creditAccount;
    }

    public void setCreditAccount(CreditAccount creditAccount) {
        this.creditAccount = creditAccount;
    }

    public List<CustomerInvoice> getCustomerInvoices() {
        return customerInvoices;
    }

    public void setCustomerInvoices(List<CustomerInvoice> customerInvoices) {
        this.customerInvoices = customerInvoices;
    }
    
    
    public List<SaleOrder> getSaleOrdersWithCIA() {
        List<SaleOrder> temp=new ArrayList<SaleOrder>();
        for(SaleOrder temp_SaleOrder:this.getSaleOrders())
        {
            if ((temp_SaleOrder.getCashInAdvance()!=null) && (temp_SaleOrder.getCashInAdvance().getCashInAdvanceAmount()>0))
                temp.add(temp_SaleOrder);
        }
        return temp;
    }
}
